package sum.MarriagesAndDivorces;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import sum.DatasetBean.MarriageDatasetBean;

import java.io.IOException;

public class SumMarriagesMapper extends Mapper<LongWritable,Text,Text, MarriageDatasetBean> {
    //int i = 0;
    Text outKey = new Text();
    MarriageDatasetBean outValue = new MarriageDatasetBean();

    @Override
    protected void map(LongWritable key, Text value,Context context) throws IOException, InterruptedException {

        //i++;
        if (key.get() == 0){
            return;
        }

        String[] fields = value.toString().split(",");
        /**
         * 北京市东城区,2022年,0.53（结婚登记数）,0.52,0.62,0.47,0.01,0.25（离婚登记数）,148,
         */
        String year = fields[1];
        outKey.set(year);
        //获得结婚登记数
        float dataset_marriages = Float.parseFloat(fields[2]);
        //获得离婚登记数
        //System.out.println("i:"+i+","+ value.toString());
        float dataset_divorces = Float.parseFloat(fields[7]);
        outValue.set(dataset_marriages,dataset_divorces);

        context.write(outKey,outValue);
    }
}
